const webpack = require("webpack");
const fs = require("fs");
let variable = fs.readFileSync("./src/variables.less").toString("utf-8");
let global = fs.readFileSync("./src/global.less").toString("utf-8");
let Home = fs.readFileSync("./src/views/Home.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let drag = fs.readFileSync("./src/components/drag/drag.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let deviceMain = fs.readFileSync("./src/views/device/deviceMain.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let energyCount = fs.readFileSync("./src/views/energy/energyCount.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let hospital = fs.readFileSync("./src/views/medicalData/hospital.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let outpatient = fs.readFileSync("./src/views/medicalData/outpatient.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let operation = fs.readFileSync("./src/views/repair/operation.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
let spaceMain = fs.readFileSync("./src/views/space/spaceMain.less").toString("utf-8").replace("@import \"@{path}/src/variables.less\";", variable);
const fileList = {
    global,
    Home,
    drag,
    deviceMain,
    energyCount,
    hospital,
    outpatient,
    operation,
    spaceMain
};

module.exports = {
    publicPath: process.env.NODE_ENV === "production" ? "/static/UnityWeb/desktop/dist/" : "/",
    lintOnSave: false,
    devServer: {
        proxy: {
            "^/login": {
                target: "http://116.236.213.2:9000"
            },
            "^/static": {
                target: "http://116.236.213.2:9000"
            },
            "^/upload": {
                target: "http://116.236.213.2:9000"
            },
            "^/file": {
                target: "http://116.236.213.2:9000"
            },
            "^/faceDatabase": {
                target: "http://116.236.213.2:9000"
            },
            "^/image": {
                target: "http://116.236.213.2:9000"
            },
            "^/s6": {
                target: "http://116.236.213.2:9000"
            },
            "^/mag": {
                target: "http://116.236.213.2:9000"
            },
            "^/Space": {
                target: "http://127.0.0.1:8000/"
            },
            "^/api": {
                target: "http://116.236.213.2:9000",
                pathRewrite: {
                    "^/api": ""
                }
            }
        }
    },
    chainWebpack: config => {
        config.resolve.alias["~"] = "node_modules";
        /* config.module.rule("vue").use("iview-loader").loader("iview-loader").tap((options) => ({
        	...options,
        	perfix: true
        })); */
        config.plugin("DefinePlugin").use(webpack.DefinePlugin).tap(t => {
            t[0] = {
                lessFiles: JSON.stringify(fileList)
            };
            return t;
        });
        return config;
    },
    css: {
		sourceMap:true,
        loaderOptions: {
            less: {
                javascriptEnabled: true,
                async: true
            }
        }
    }
};
